|
|
|
|
|
|
|
Listing 9.19. Coding the cmdIndex_Click event. |
|
|
|
|
|
|
|
|
Private Sub cmdIndex_Click()
'
' create a new index and display its properties
'
Dim ws As Workspace
Dim db As Database
Dim td As TableDef
Dim ix As Index
Dim fl As Field
Dim pr As Property
'
Dim strDBName As String
Dim strTDName As String
Dim strFLName As String
Dim strIXName As String
Dim strMsg As String
'
' init vars
strDBName = App.Path & "\NewDB.mdb"
strTDName = "NewTable"
strFLName = "NewField"
strIXName = "PKNewTable"
'
' create db and table
cmdCreateTable_Click
'
' open ws, db and table
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(strDBName)
Set td = db.TableDefs(strTDName)
'
' now create an index
Set ix = td.CreateIndex(strIXName)
Set fl = ix.CreateField(strFLName)
ix.Required = True
ix.Primary = True
'
' add field to index's fields collection
ix.Fields.Append fl
'
' add index to table's index collection
td.Indexes.Append ix
'
' now show index properties
strMsg = ""
For Each pr In ix.Properties
strMsg = strMsg & pr.Name
strMsg = strMsg & " = "
strMsg = strMsg & pr.Value
strMsg = strMsg & " {"
strMsg = strMsg & ShowType(pr.Type)
strMsg = strMsg & "}"
strMsg = strMsg & vbCrLf |
|
|
|
|
|